package com.suneee.logistic.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.suneee.context.page.Page;
import com.suneee.logistic.dao.LogisticDao;
import com.suneee.logistic.entity.Logistic;
import com.suneee.logistic.entity.LogisticDTO;
import com.suneee.orm.GenericDao;
import com.suneee.orm.util.WhereClauseBuilder;


@Repository("logisticDao")
public class LogisticDaoImpl extends GenericDao<Logistic, String> implements LogisticDao {

	@Override
	public boolean existsName(String companyName) {
		return this.exists("company_name", companyName);
	}

	/**
	 * 判断是否重复
	 * 
	 * @param name
	 * @param value
	 * @return
	 */
	private boolean exists(Object name, Object value) {
		List<Logistic> list = this.selectWhere(name + " = ? ", value);
		return list != null && list.size() > 0;
	}

	@Override
	public boolean existsId(String logisticId) {
		return this.exists("company_code", logisticId);
	}

	@Override
	public Page<Logistic> listLogistic(LogisticDTO dto) {
		WhereClauseBuilder builder = new WhereClauseBuilder();
		return selectWhere(builder.getSql(), dto, builder.getArgs()); 
	}
	@Override
	public List<Logistic> listLogisticEn(LogisticDTO dto) {
		return this.select();
	}
}
